
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>使用矩阵键盘控制数码管显示 · WQ GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-callouts/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/styles.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../verilog/introduction.html" />
    
    
    <link rel="prev" href="keyboards_waterlight.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../lab0/introduction.html">
            
                <a href="../lab0/introduction.html">
            
                    
                    LAB0: 工欲善其事 必先利其器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../lab0/FPGAintro.html">
            
                <a href="../lab0/FPGAintro.html">
            
                    
                    FPGA 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../lab0/whyFPGA.html">
            
                <a href="../lab0/whyFPGA.html">
            
                    
                    为什么是 FPGA？
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../lab0/design_method.html">
            
                <a href="../lab0/design_method.html">
            
                    
                    设计方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../lab0/board_intro.html">
            
                <a href="../lab0/board_intro.html">
            
                    
                    平台介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../lab0/intro_tools.html">
            
                <a href="../lab0/intro_tools.html">
            
                    
                    软硬件关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../lab0/keil.html">
            
                <a href="../lab0/keil.html">
            
                    
                    Keil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../lab0/vivado.html">
            
                <a href="../lab0/vivado.html">
            
                    
                    Vivado
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../lab0/modelsim.html">
            
                <a href="../lab0/modelsim.html">
            
                    
                    Modelsim
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../lab1/introduction.html">
            
                <a href="../lab1/introduction.html">
            
                    
                    LAB1: "施法"让 CPU 动起来
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../lab1/sec_1.html">
            
                <a href="../lab1/sec_1.html">
            
                    
                    ARM 汇编回顾
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../lab1/sec_2.html">
            
                <a href="../lab1/sec_2.html">
            
                    
                    搭建 Keil 环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../lab1/sec_3.html">
            
                <a href="../lab1/sec_3.html">
            
                    
                    运行吧, 第一个汇编程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../lab1/sec_5.html">
            
                <a href="../lab1/sec_5.html">
            
                    
                    栈 - 函数调用的指挥官
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../lab1/sec_6.html">
            
                <a href="../lab1/sec_6.html">
            
                    
                    自己动手, 理解函数调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../lab2/introduction.html">
            
                <a href="../lab2/introduction.html">
            
                    
                    LAB2: "点石成金" - 实现你的首个 SoC
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../lab2/sec_1.html">
            
                <a href="../lab2/sec_1.html">
            
                    
                    硬件部分说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../lab2/sec_2.html">
            
                <a href="../lab2/sec_2.html">
            
                    
                    搭建 Keil 工程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../lab2/sec_3.html">
            
                <a href="../lab2/sec_3.html">
            
                    
                    Modelsim 仿真
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../lab2/sec_4.html">
            
                <a href="../lab2/sec_4.html">
            
                    
                    下载比特流到 FPGA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../lab2/sec_5.html">
            
                <a href="../lab2/sec_5.html">
            
                    
                    将硬件固化到开发板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../lab2/sec_6.html">
            
                <a href="../lab2/sec_6.html">
            
                    
                    使用 Keil 调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../lab3/introduction.html">
            
                <a href="../lab3/introduction.html">
            
                    
                    LAB3: "灯, 等灯, 等灯"-流水灯的几种点法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../lab3/data_storage.html">
            
                <a href="../lab3/data_storage.html">
            
                    
                    数据存储器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../lab3/GPIO.html">
            
                <a href="../lab3/GPIO.html">
            
                    
                    GPIO外设实现流水灯
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../lab3/WaterLight.html">
            
                <a href="../lab3/WaterLight.html">
            
                    
                    硬件流水灯
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="introduction.html">
            
                <a href="introduction.html">
            
                    
                    LAB4: 如何召唤"沉睡的软件"
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="keyboards.html">
            
                <a href="keyboards.html">
            
                    
                    矩阵键盘原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="keyboards_waterlight.html">
            
                <a href="keyboards_waterlight.html">
            
                    
                    使用矩阵键盘4个按键控制流水灯模式
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.3" data-path="keyboards_led.html">
            
                <a href="keyboards_led.html">
            
                    
                    使用矩阵键盘控制数码管显示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../verilog/introduction.html">
            
                <a href="../verilog/introduction.html">
            
                    
                    附录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../verilog/grammar.html">
            
                <a href="../verilog/grammar.html">
            
                    
                    Verilog基本语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../verilog/enable_signal.html">
            
                <a href="../verilog/enable_signal.html">
            
                    
                    使能信号
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../verilog/decoder.html">
            
                <a href="../verilog/decoder.html">
            
                    
                    总线译码器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../faq/introduction.html">
            
                <a href="../faq/introduction.html">
            
                    
                    常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../add_notice.html">
            
                <a href="../add_notice.html">
            
                    
                    补充通知
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../about/introduction.html">
            
                <a href="../about/introduction.html">
            
                    
                    About
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >使用矩阵键盘控制数码管显示</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x63A7;&#x5236;&#x6570;&#x7801;&#x7BA1;&#x663E;&#x793A;">&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x63A7;&#x5236;&#x6570;&#x7801;&#x7BA1;&#x663E;&#x793A;</h2>
<!-- -->
<div class="panel panel-success"><div class="panel-heading"><h5 class="panel-title" id="&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x63A7;&#x5236;&#x6570;&#x7801;&#x7BA1;&#x663E;&#x793A;"><i class="fa fa-flag"></i> &#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x63A7;&#x5236;&#x6570;&#x7801;&#x7BA1;&#x663E;&#x793A;</h5></div><div class="panel-body"><p>&#x5728;&#x8FD9;&#x6B21;&#x5B9E;&#x9A8C;&#x4E2D;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x628A;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x7684;&#x5168;&#x90E8; 16 &#x4E2A;&#x6309;&#x952E;&#x8FDE;&#x63A5;&#x5230; IRQ0 &#x7AEF;&#x53E3;&#x4E0A;, &#x5F53;&#x4EFB;&#x4F55;&#x4E00;&#x4E2A;&#x6309;&#x952E;&#x88AB;&#x6309;&#x4E0B;&#x65F6;, CPU &#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7A0B;&#x5E8F;, &#x8BFB;&#x53D6;&#x6309;&#x952E;&#x4FE1;&#x606F;, &#x6839;&#x636E;&#x6309;&#x4E0B;&#x7684;&#x6309;&#x952E;&#x7F16;&#x53F7;&#x5728;&#x6570;&#x7801;&#x7BA1;&#x4E0A;&#x663E;&#x793A;&#x5BF9;&#x5E94;&#x7684;&#x6570;&#x503C;.</p></div></div>
<h3 id="&#x5916;&#x8BBE;&#x7B80;&#x4ECB;">&#x5916;&#x8BBE;&#x7B80;&#x4ECB;</h3>
<p>&#x6570;&#x7801;&#x7BA1;&#x663E;&#x793A;&#x7684;&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x89C1;&#x5DE5;&#x7A0B;&#x6587;&#x4EF6;&#x5939;&#x4E0B; &quot;Segdisp.v&#x3001;seg_led_decoder.v&#x3001;seg_sel_decoder.v&quot; &#x6587;&#x4EF6;.</p>
<p>&#x7531;&#x4E8E;&#x6240;&#x6709;&#x6309;&#x952E;&#x8FDE;&#x63A5;&#x5230;&#x540C;&#x4E00;&#x4E2A;&#x4E2D;&#x65AD;&#x7AEF;&#x53E3;, &#x56E0;&#x6B64;&#x952E;&#x76D8;&#x5916;&#x8BBE;&#x9664;&#x4E86;&#x57FA;&#x672C;&#x7684;&#x6D88;&#x6296;&#x68C0;&#x6D4B;&#x6A21;&#x5757;&#x4EE5;&#x5916;, &#x8FD8;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x5BC4;&#x5B58;&#x5668;&#x7EC4;&#x5C06;&#x88AB;&#x6309;&#x4E0B;&#x7684;&#x952E;&#x76D8;&#x7684;&#x5E8F;&#x53F7;&#x8BB0;&#x5F55;&#x4E0B;&#x6765;. &#x672C;&#x8282;&#x7528;&#x5230;&#x4E86;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x7684;&#x5168;&#x90E8;&#x6309;&#x952E;, &#x56E0;&#x6B64;&#x4E0D;&#x80FD;&#x50CF;&#x4E0A;&#x4E00;&#x4E2A;&#x5B9E;&#x9A8C;&#x4E2D;&#x4E3A;&#x4E86;&#x4F7F;&#x7528;&#x67D0;&#x4E00;&#x884C;&#x7684; 4 &#x4E2A;&#x6309;&#x952E;, &#x5C06;&#x8BE5;&#x884C;&#x7684;&#x884C;&#x4FE1;&#x53F7;&#x7EBF;&#x62C9;&#x4F4E;. &#x4E3A;&#x4E86;&#x5B9E;&#x73B0;&#x5BF9;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x5168;&#x90E8; 16 &#x4E2A;&#x6309;&#x952E;&#x7684;&#x68C0;&#x6D4B;, &#x9700;&#x8981;&#x8FDB;&#x884C;&#x626B;&#x63CF;. </p>
<p>&#x7531;&#x4E8E; FPGA &#x677F;&#x8F7D;&#x65F6;&#x949F;&#x9891;&#x7387;&#x4E3A; 50MHz, &#x6240;&#x4EE5;&#x8FD8;&#x9700;&#x8981;&#x5148;&#x5BF9;&#x65F6;&#x949F;&#x4FE1;&#x53F7;&#x5206;&#x9891;&#x5F97;&#x5230;&#x626B;&#x63CF;&#x65F6;&#x949F;&#x4FE1;&#x53F7;, &#x6309;&#x626B;&#x63CF;&#x65F6;&#x949F;&#x4FE1;&#x53F7;&#x5468;&#x671F;&#x6027;&#x5730;&#x6539;&#x53D8;&#x884C;&#x4FE1;&#x53F7;&#x7EBF;&#x7684;&#x503C;. &#x5F53;&#x7B2C;&#x4E00;&#x884C;&#x884C;&#x4FE1;&#x53F7;&#x7EBF;&#x4E3A;&#x4F4E;&#x7535;&#x5E73;&#x65F6;, &#x6B64;&#x65F6;&#x68C0;&#x6D4B;&#x5217;&#x4FE1;&#x53F7;&#x7684;&#x503C;&#x4FBF;&#x53EF;&#x5224;&#x65AD;&#x51FA;&#x662F;&#x7B2C;&#x4E00;&#x884C;&#x7684;&#x67D0;&#x4E2A;&#x6309;&#x952E;&#x88AB;&#x6309;&#x4E0B;. &#x4EE5;&#x6B64;&#x7C7B;&#x63A8;, &#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x626B;&#x63CF;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x68C0;&#x6D4B;&#x77E9;&#x9635;&#x952E;&#x76D8; 16 &#x4E2A;&#x6309;&#x952E;&#x4E2D;&#x662F;&#x54EA;&#x4E00;&#x4E2A;&#x6309;&#x952E;&#x88AB;&#x6309;&#x4E0B;. &#x9664;&#x4E86;&#x626B;&#x63CF;&#x6A21;&#x5757;&#x4EE5;&#x5916;, &#x952E;&#x76D8;&#x6A21;&#x5757;&#x8FD8;&#x5305;&#x62EC;&#x6D88;&#x6296;&#x6A21;&#x5757;&#x548C;&#x8BB0;&#x5F55;&#x6309;&#x952E;&#x4FE1;&#x606F;&#x7684;&#x5BC4;&#x5B58;&#x5668;&#x7EC4;. </p>
<p>&#x6700;&#x540E;&#x5B9E;&#x73B0;&#x7684;&#x952E;&#x76D8;&#x5916;&#x8BBE;&#x6A21;&#x5757;&#x4E2D;, &#x628A;&#x6BCF;&#x4E2A;&#x6309;&#x952E;&#x7684;&#x8109;&#x51B2;&#x4FE1;&#x53F7; key_pulse &#x901A;&#x8FC7;&#x6216;&#x8FD0;&#x7B97;&#x4EE5;&#x540E;, &#x5F97;&#x5230;&#x952E;&#x76D8;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;key_interrupt. &#x53EA;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x6309;&#x952E;&#x88AB;&#x6309;&#x4E0B;, &#x4E2D;&#x65AD;&#x4FE1;&#x53F7;&#x90FD;&#x5C06;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x8109;&#x51B2;, &#x4F7F;CPU&#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7A0B;&#x5E8F;. </p>
<!-- -->
<div class="panel panel-success"><div class="panel-heading"><h5 class="panel-title" id="&#x63D0;&#x793A;"><i class="fa fa-lightbulb-o"></i> &#x63D0;&#x793A;</h5></div><div class="panel-body"><p>&#x53EF;&#x4EE5;&#x770B;&#x51FA;, &#x672C;&#x8282;&#x4ECB;&#x7ECD;&#x7684;&#x65B9;&#x6CD5;&#x4E2D;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;&#x548C;&#x4E0A;&#x4E00;&#x8282;&#x4E2D;&#x7684;&#x6709;&#x5F88;&#x5927;&#x4E0D;&#x540C;, &#x5E94;&#x5F53;&#x8BA4;&#x771F;&#x4F53;&#x4F1A;!</p></div></div>
<h3 id="soc&#x786C;&#x4EF6;&#x90E8;&#x5206;">SoC&#x786C;&#x4EF6;&#x90E8;&#x5206;</h3>
<p>&#x4E0A;&#x4E00;&#x4E2A;&#x5B9E;&#x9A8C;&#x4E2D;&#x6309;&#x952E;&#x6A21;&#x5757;&#x7684;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;&#x4E3A; 4 &#x4F4D; key_interrupt &#x4FE1;&#x53F7;, &#x672C;&#x5B9E;&#x9A8C;&#x4E2D;&#x8BE5;&#x4FE1;&#x53F7;&#x4E3A; 1 &#x4F4D;, &#x56E0;&#x6B64;&#x5728; CortexM0_SoC.v &#x6587;&#x4EF6;&#x505A;&#x5982;&#x4E0B;&#x4FEE;&#x6539;.</p>
<pre><code class="lang-verilog"><span class="hljs-keyword">wire</span> [<span class="hljs-number">31</span>:<span class="hljs-number">0</span>] IRQ;
<span class="hljs-keyword">wire</span> [<span class="hljs-number">3</span>:<span class="hljs-number">0</span>] key_interrupt;
<span class="hljs-comment">/*Connect the IRQ with keyboard*/</span>
<span class="hljs-keyword">assign</span> IRQ = {<span class="hljs-number">28</span>&apos;b0,key_interrupt};
<span class="hljs-comment">/***************************/</span>
</code></pre>
<p>&#x6539;&#x4E3A;:</p>
<pre><code class="lang-verilog"><span class="hljs-keyword">wire</span> [<span class="hljs-number">31</span>:<span class="hljs-number">0</span>] IRQ;
<span class="hljs-keyword">wire</span> key_interrupt;
<span class="hljs-comment">/*Connect the IRQ with keyboard*/</span>
<span class="hljs-keyword">assign</span> IRQ = {<span class="hljs-number">31</span>&apos;d0,key_interrupt};
<span class="hljs-comment">/***************************/</span>
</code></pre>
<p>&#x7136;&#x540E;&#x5728;&#x4E0A;&#x4E00;&#x4E2A;&#x5B9E;&#x9A8C;&#x7684; vivado &#x7EA6;&#x675F;&#x6587;&#x4EF6;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x6DFB;&#x52A0;&#x5BF9;&#x6570;&#x7801;&#x7BA1;&#x7684;&#x7EA6;&#x675F;.</p>
<h3 id="&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x4E0E;-c-&#x7F16;&#x7A0B;">&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x4E0E; C &#x7F16;&#x7A0B;</h3>
<p>&#x7531;&#x4E8E;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;&#x7684;&#x53D8;&#x5316;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x5BF9;&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4FEE;&#x6539;. &#x4E0A;&#x4E00;&#x4E2A;&#x5B9E;&#x9A8C;&#x4E2D;&#x5DF2;&#x7ECF;&#x4ECB;&#x7ECD;&#x8FC7; _main &#x51FD;&#x6570;&#x548C; __user_initial_stackheap &#x51FD;&#x6570;, &#x5728;&#x672C;&#x5B9E;&#x9A8C;&#x4E2D;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;&#x4E0E;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;&#x5373;&#x53EF;.</p>
<p>&#x4FEE;&#x6539;__Vector&#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-cpp">__Vectors     DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler
                DCD     <span class="hljs-number">0</span>                           ; NMI Handler
                DCD     <span class="hljs-number">0</span>                          ; Hard Fault Handler
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                           ; SVCall Handler
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; Reserved
                DCD     <span class="hljs-number">0</span>                        ; PendSV Handler
                DCD     <span class="hljs-number">0</span>                          ; SysTick Handler
                DCD     Keyboard_Handler        ; IRQ0 Handler
</code></pre>
<p>&#x73B0;&#x5728;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;, &#x56E0;&#x6B64;&#x8FD8;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x5165;&#x53E3;:</p>
<pre><code class="lang-c">KEY0_Handler    PROC
                EXPORT KEY0_Handler            [WEAK]
               IMPORT KEY0
               PUSH    {R0,R1,R2,LR}
                BL        KEY0
               POP        {R0,R1,R2,PC}
                ENDP

KEY1_Handler    PROC
                EXPORT KEY1_Handler            [WEAK]
               IMPORT KEY1
               PUSH    {R0,R1,R2,LR}
                BL        KEY1
               POP        {R0,R1,R2,PC}
                ENDP

KEY2_Handler    PROC
                EXPORT KEY2_Handler            [WEAK]
               IMPORT KEY2
               PUSH    {R0,R1,R2,LR}
                BL        KEY2
               POP        {R0,R1,R2,PC}
                ENDP

KEY3_Handler    PROC
                EXPORT KEY3_Handler            [WEAK]
               IMPORT KEY3
               PUSH    {R0,R1,R2,LR}
                BL        KEY3
               POP        {R0,R1,R2,PC}
                ENDP
</code></pre>
<p>&#x6539;&#x4E3A;:</p>
<pre><code>Keyboard_Handler    PROC
                    EXPORT Keyboard_Handler            [WEAK]
                   IMPORT KEY_ISR
                   PUSH    {R0,R1,R2,LR}
                    BL        KEY_ISR
                   POP    {R0,R1,R2,PC}
                    ENDP
</code></pre><p>&#x7136;&#x540E;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x5B9A;&#x4E49;&#x5916;&#x8BBE;&#x7684;&#x5730;&#x5740;, &#x4EE5;&#x53CA;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x7684;&#x51FD;&#x6570;, &#x53C2;&#x8003; CMSIS &#x7F16;&#x5199;&#x81EA;&#x5DF1;&#x5934;&#x6587;&#x4EF6;. &#x5177;&#x4F53;&#x4EE3;&#x7801;&#x89C1; &quot;/Task4/key_led/keil/code_def.h&quot;.</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdint.h&gt;</span></span>

<span class="hljs-comment">//INTERRUPT DEF</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> NVIC_CTRL_ADDR (*(volatile unsigned *)0xe000e100)</span>

<span class="hljs-comment">//KEYBOARD DEF</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Keyboard_keydata_clear (*(volatile unsigned *)0x40000000)</span>

<span class="hljs-comment">//SEGDISP DEF</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Segdisp_data (*(volatile unsigned *)0x40000010)</span>

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY_ISR</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>;
</code></pre>
<p>&#x5176;&#x4E2D; Keyboard_keydata_clear &#x8FDE;&#x5230;&#x952E;&#x76D8;&#x6A21;&#x5757;&#x4E2D;&#x7684; clear &#x7AEF;&#x53E3;, &#x7528;&#x4E8E;&#x6309;&#x952E;&#x4FE1;&#x606F;&#x5BC4;&#x5B58;&#x5668;&#x7EC4;&#x7684;&#x6E05;&#x96F6;. Segdisp_data &#x4E3A;&#x6570;&#x7801;&#x7BA1;&#x4E0A;&#x9700;&#x8981;&#x663E;&#x793A;&#x7684;&#x6570;&#x636E;. &#x4E2D;&#x65AD;&#x5904;&#x7406;&#x51FD;&#x6570; KEY_ISR &#x5C06;&#x53D8;&#x91CF; key_flag &#x7684;&#x503C;&#x6539;&#x4E3A; 1, &#x7528;&#x4E8E; C &#x8BED;&#x8A00;&#x7A0B;&#x5E8F;&#x4E2D;&#x5224;&#x65AD;&#x662F;&#x5426;&#x6709;&#x6309;&#x952E;&#x88AB;&#x6309;&#x4E0B;&#x4EA7;&#x751F;&#x4E86;&#x4E2D;&#x65AD;, &#x5177;&#x4F53;&#x89C1; &quot;/Task4/key_led/keil/keyboard.c&quot;.</p>
<pre><code class="lang-c"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY_ISR</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
    key_flag = <span class="hljs-number">1</span>;
}
</code></pre>
<p>&#x6700;&#x540E;, &#x7F16;&#x5199;&#x4E3B;&#x51FD;&#x6570;&#x6587;&#x4EF6;, &#x5177;&#x4F53;&#x89C1; &quot;/Task4/key_led/keil/main.c&quot;, &#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;, &#x5728;&#x4E2D;&#x65AD;&#x542F;&#x52A8;&#x4E4B;&#x524D;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x80FD;&#x6240;&#x7528;&#x5230;&#x7684;&#x4E2D;&#x65AD;.</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;code_def.h&quot;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdint.h&gt;</span></span>

<span class="hljs-keyword">extern</span> <span class="hljs-keyword">uint32_t</span> key_flag;

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
</span>{   
    NVIC_CTRL_ADDR    = <span class="hljs-number">1</span>;

    <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>){
          <span class="hljs-keyword">while</span>(!key_flag);
            <span class="hljs-keyword">uint32_t</span> din;
            din = Keyboard_keydata_clear;
            <span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">int</span> ans = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">16</span>; i++) {
                <span class="hljs-keyword">if</span> ((din &gt;&gt; i) &amp; <span class="hljs-number">1</span>) {
                     ans = i;
                    Segdisp_data = <span class="hljs-number">16</span> + ans; <span class="hljs-comment">//enable</span>
                    <span class="hljs-keyword">break</span>;
                }
            }
        key_flag = <span class="hljs-number">0</span>;
        Keyboard_keydata_clear = <span class="hljs-number">1</span>;
    }
}
</code></pre>
<p>&#x5F53;&#x4EFB;&#x4E00;&#x6309;&#x952E;&#x88AB;&#x6309;&#x4E0B;&#x540E;, &#x952E;&#x76D8;&#x6A21;&#x5757;&#x4F1A;&#x4EA7;&#x751F;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;, CPU &#x8FDB;&#x5165;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7A0B;&#x5E8F;, key_flag &#x7684;&#x503C;&#x53D8;&#x4E3A; 1. &#x6B64;&#x65F6;, main &#x51FD;&#x6570;&#x4E2D;&#x5185;&#x5C42; while &#x5FAA;&#x73AF;&#x88AB;&#x8DF3;&#x8FC7;, &#x5F00;&#x59CB;&#x8BFB;&#x53D6;&#x952E;&#x76D8;&#x7684;&#x503C;. &#x952E;&#x76D8;&#x5BC4;&#x5B58;&#x5668;&#x7EC4;&#x7684;&#x503C;&#x88AB;&#x8BFB;&#x5230;&#x53D8;&#x91CF; din &#x4E2D;, &#x63A5;&#x7740;&#x7528;&#x4E00;&#x4E2A; for &#x5FAA;&#x73AF;&#x627E;&#x51FA;&#x54EA;&#x4E00;&#x4F4D;&#x4E3A; 1, &#x8BB0;&#x5F55;&#x5728;&#x53D8;&#x91CF; ans &#x4E2D;, &#x540C;&#x65F6;&#x5411;&#x6570;&#x7801;&#x7BA1;&#x5916;&#x8BBE;&#x5199;&#x503C; 16+ans, &#x8DF3;&#x51FA;&#x5FAA;&#x73AF;. &#x56E0;&#x4E3A;&#x6570;&#x7801;&#x7BA1;&#x6A21;&#x5757;&#x4E2D; 5 &#x4F4D;&#x8F93;&#x5165;&#x6570;&#x636E;&#x4E2D;&#x6700;&#x9AD8;&#x4F4D;&#x662F;&#x4F7F;&#x80FD;&#x4FE1;&#x53F7; (&#x8868;&#x793A;&#x6570;&#x636E;&#x8F93;&#x5165;&#x662F;&#x5426;&#x6709;&#x6548;), &#x56E0;&#x6B64;&#x5728;&#x5199;&#x5165;&#x4F4E;&#x56DB;&#x4F4D;&#x7684;&#x6570;&#x636E;&#x57FA;&#x7840;&#x4E0A;, &#x8FD8;&#x9700;&#x8981;&#x52A0;&#x4E0A; 16, &#x8BA9;&#x4F7F;&#x80FD;&#x4FE1;&#x53F7;&#x6709;&#x6548;. &#x6700;&#x540E;&#x5C31;&#x662F;&#x5728;&#x6BCF;&#x6B21;&#x5FAA;&#x73AF;&#x5904;&#x7406;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#x5C06; key_flag &#x7B49;&#x53D8;&#x91CF;&#x4EE5;&#x53CA;&#x952E;&#x76D8;&#x5916;&#x8BBE;&#x7684;&#x5BC4;&#x5B58;&#x5668;&#x7EC4;&#x6E05;&#x96F6;.</p>
<h3 id="&#x8C03;&#x8BD5;&#x4E0E;&#x8FD0;&#x884C;&#x7ED3;&#x679C;">&#x8C03;&#x8BD5;&#x4E0E;&#x8FD0;&#x884C;&#x7ED3;&#x679C;</h3>
<p>&#x5C06;&#x76F8;&#x5173;&#x7684; Verilog &#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x5230; Vivado &#x5DE5;&#x7A0B;&#x4E2D;, &#x5C06; Vivado &#x751F;&#x6210;&#x7684;&#x6BD4;&#x7279;&#x6D41; (bitstream) &#x6587;&#x4EF6;&#x4E0B;&#x8F7D;&#x5230; FPGA &#x5F00;&#x53D1;&#x677F;&#x4E0A;, &#x4F7F;&#x7528; Keil &#x8C03;&#x8BD5;. &#x5728;&#x6309;&#x4E0B;&#x6309;&#x952E;&#x65F6;, &#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6570;&#x7801;&#x7BA1;&#x4E0A;&#x663E;&#x793A;&#x4E86;&#x6309;&#x952E;&#x7F16;&#x53F7; (&#x6700;&#x5DE6;&#x8FB9;&#x7684;&#x6570;&#x7801;&#x7BA1;), &#x4E4B;&#x524D;&#x7684;&#x663E;&#x793A;&#x7ED3;&#x679C;&#x53F3;&#x79FB;&#x4E00;&#x4F4D;.</p>
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> By UESTC Intelligent Chip and System Design Lab. &#x91C7;&#x7528;<a href="https://creativecommons.org/licenses/by-nc-sa/3.0/cn/" target="_blank">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; &#x7F72;&#x540D;-&#x975E;&#x5546;&#x4E1A;&#x6027;&#x4F7F;&#x7528;-&#x76F8;&#x540C;&#x65B9;&#x5F0F;&#x5171;&#x4EAB; 3.0 &#x4E2D;&#x56FD;&#x5927;&#x9646; &#x8BB8;&#x53EF;&#x534F;&#x8BAE;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> &#x6B64;&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E; 2022-04-29 21:55:31 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="keyboards_waterlight.html" class="navigation navigation-prev " aria-label="Previous page: 使用矩阵键盘4个按键控制流水灯模式">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../verilog/introduction.html" class="navigation navigation-next " aria-label="Next page: 附录">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"使用矩阵键盘控制数码管显示","level":"1.6.3","depth":2,"next":{"title":"附录","level":"1.7","depth":1,"path":"verilog/introduction.md","ref":"verilog/introduction.md","articles":[{"title":"Verilog基本语法","level":"1.7.1","depth":2,"path":"verilog/grammar.md","ref":"verilog/grammar.md","articles":[]},{"title":"使能信号","level":"1.7.2","depth":2,"path":"verilog/enable_signal.md","ref":"verilog/enable_signal.md","articles":[]},{"title":"总线译码器","level":"1.7.3","depth":2,"path":"verilog/decoder.md","ref":"verilog/decoder.md","articles":[]}]},"previous":{"title":"使用矩阵键盘4个按键控制流水灯模式","level":"1.6.2","depth":2,"path":"lab4/keyboards_waterlight.md","ref":"lab4/keyboards_waterlight.md","articles":[]},"dir":"ltr"},"config":{"plugins":["intopic-toc","callouts","page-footer-ex","-livereload","theme-comscore","-sharing"],"styles":{"website":"styles/styles.css"},"pluginsConfig":{"callouts":{"important":{"alert":"danger","picto":"fa-bullhorn"},"danger":{"alert":"danger","picto":"fa-exclamation-circle"},"question":{"alert":"info","picto":"fa-question-circle"},"hint":{"alert":"success","picto":"fa-lightbulb-o"},"showTypeInHeader":false,"must":{"alert":"warning","picto":"fa-edit"},"flag":{"alert":"success","picto":"fa-flag"},"info":{"alert":"info","picto":"fa-info-circle"},"note":{"alert":"info","picto":"fa-edit"},"fread":{"alert":"info","picto":"fa-comment"}},"intopic-toc":{"isCollapsed":true,"isScrollspyActive":true,"label":"导航","maxDepth":6,"mode":"nested","selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4","visible":true},"page-footer-ex":{"copyright":"By UESTC Intelligent Chip and System Design Lab. 采用[知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议](https://creativecommons.org/licenses/by-nc-sa/3.0/cn/)发布","markdown":true,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"此页面修订于"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"WQ GitBook","gitbook":"*"},"file":{"path":"lab4/keyboards_led.md","mtime":"2022-04-29T13:55:31.046Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-16T07:13:54.762Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

